package com.jiai.cloud.community.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jiai.cloud.base.exception.ServiceException;
import com.jiai.cloud.base.tools.RestResultGenerator;
import com.jiai.cloud.community.entity.TClassify;
import com.jiai.cloud.community.service.ITClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.naming.Name;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-06-07
 */
@RestController
@RequestMapping("/api/v1/tClassify")
public class TClassifyController {
    @Autowired
    private ITClassifyService itClassifyService;

    @RequestMapping(value = "/addtClassify" ,method = RequestMethod.POST,produces = {"application/json;charset=UTF-8"})
    public Object addTemplate(TClassify classify) throws ServiceException {
        try {
            itClassifyService.insertOrUpdate(classify);
            return RestResultGenerator.genSuccessResult(classify);
        } catch (Exception e) {
            throw new ServiceException("编辑失敗", e.getMessage());
        }
    }
    @RequestMapping(value = "/del", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Object deleteId( String classifyName) throws ServiceException{
        try{

            itClassifyService.delete(new EntityWrapper<TClassify>().eq("classifyName",classifyName));
            return RestResultGenerator.genSuccessResult(classifyName);
        }catch (Exception e){
            throw new ServiceException("删除失敗", e.getMessage());
        }
    }
}
